package com.jic.manager.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.AdminOperate;
import com.jic.manager.common.util.BeanUtil;
import com.jic.manager.entity.MerchantWeBankFinance;
import com.jic.manager.mapper.MerchantWeBankFinanceMapper;
import com.jic.manager.request.MerchantWeBankFinanceRequest;
import com.jic.manager.service.MerchantWeBankFinanceService;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商户财务信息表
 * @author : 
 * @email : 
 * @since : 2020-11-28 11:08:40
 * @version : v1.0.0
 */
@Service
public class MerchantWeBankFinanceServiceImpl implements MerchantWeBankFinanceService{

    @Autowired
    private MerchantWeBankFinanceMapper merchantWeBankFinanceMapper;

    @Override
    public long insert(MerchantWeBankFinance merchantWeBankFinance) {
        long flag = merchantWeBankFinanceMapper.insert(merchantWeBankFinance);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return merchantWeBankFinanceMapper.delete(id);
    }

    @Override
    public long update(MerchantWeBankFinance merchantWeBankFinance) {
        return merchantWeBankFinanceMapper.update(merchantWeBankFinance);
    }

    @Override
    public MerchantWeBankFinance queryByPrimaryKey(Long id){
        return merchantWeBankFinanceMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MerchantWeBankFinance> query(MerchantWeBankFinance merchantWeBankFinance){
        return merchantWeBankFinanceMapper.query(merchantWeBankFinance);
    }

    @Override
    public PageResult<MerchantWeBankFinance> queryPage(MerchantWeBankFinance merchantWeBankFinance, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MerchantWeBankFinance> list = merchantWeBankFinanceMapper.queryPage(startIndex, pageQuery.getLimit(), merchantWeBankFinance);
        long count = merchantWeBankFinanceMapper.queryPageCount(merchantWeBankFinance);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    /**
     * 编辑商户财务信息
     * @param request
     * @return
     */
    @Override
    public Long updateMerchantFinanceInfo(MerchantWeBankFinanceRequest request) {
        MerchantWeBankFinance merchantWeBankFinance = BeanUtil.copy(request,MerchantWeBankFinance.class);
        AdminOperate adminOperate = request.getAdminOperate();
        merchantWeBankFinance.setUpdater(adminOperate.getOperator());
        merchantWeBankFinance.setUpdaterName(adminOperate.getOperateName());
        merchantWeBankFinanceMapper.updateByMerchantId(merchantWeBankFinance);
        return merchantWeBankFinance.getId();
    }

    /**
     * 新增财务信息
     * @param request
     * @return
     */
    @Override
    public Long addMerchantFinanceInfo(MerchantWeBankFinanceRequest request) {
        MerchantWeBankFinance merchantWeBankFinance = BeanUtil.copy(request,MerchantWeBankFinance.class);
        AdminOperate adminOperate = request.getAdminOperate();
        merchantWeBankFinance.setCreator(adminOperate.getOperator());
        merchantWeBankFinance.setCreatorName(adminOperate.getOperateName());
        merchantWeBankFinance.setDeptId(adminOperate.getDeptId());
        return merchantWeBankFinanceMapper.insert(merchantWeBankFinance);
    }


    /**
     * 查询商户财务信息
     * @param merchantId
     * @return
     */
    @Override
    public MerchantWeBankFinance getMerchantFinanceByMerchantId(Long merchantId){
        return merchantWeBankFinanceMapper.getMerchantFinanceByMerchantId(merchantId);
    }
}